package com.yellow.courierservice.controller;

import com.yellow.courierservice.feign.OrderFeignService;
import com.yellow.courierservice.service.CourierProfileService;
import com.yellow.courierservice.service.DeliveryAreaService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * @author: hy
 * @create: 2024-04-22
 */
@RestController
@Slf4j
@CrossOrigin(origins = "*", maxAge = 3600)
@RequestMapping("/courier")
public class CourierController {
    @Resource
    private CourierProfileService courierProfileService ;
    @Resource
    private DeliveryAreaService deliveryAreaService;
    @Resource
    private OrderFeignService orderFeignService;
    @GetMapping("/getCourier/{name}")
    public ResponseEntity<?> getCourierProfileByCourierName(@PathVariable(value = "name") String courierName) {
        return ResponseEntity.ok(courierProfileService.getCourierProfileByCourierName(courierName));
    }

    @GetMapping("/getAreaName/{orderId}")
    public String getAreaNameByCourierName(@PathVariable(value = "orderId") Integer orderId){
        String courierName = orderFeignService.getCourierNameByOrderId(orderId);
        return deliveryAreaService.getDeliveryAreaByCourierName(courierName);
    }

    @GetMapping("/getId/{name}")
    public Integer getCourierIdByCourierName(@PathVariable(value = "name") String courierName){
        return courierProfileService.getCourierIdByCourierName(courierName);
    }
}
